var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("UIBase"),
    s = t("UIConfig"),
    c = t("UIManager"),
    p = t("GameSkillItem"),
    l = t("GameEm"),
    d = t("AdView"),
    u = cc._decorator,
    h = u.ccclass,
    f =
        (u.property,
        u.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.listData = [];
                e.lastIndex = -1;
                return e;
            }
            e.prototype.onShowEnd = function () {
                AdView.showAd(function () {
                    console.log("打开店铺升级页面.展示嵌入");
                }, d.AdTypeEm.implant);
                EVUIEffView.on(EVUIEffView.checkCostUI, this.updateAllViewCost.bind(this), this);
                EVUIEffView.on(EVUIEffView.updateSkillTaskItem, this.uplockIndex.bind(this), this);
                QAudio.play(QAudio.ui_popup);
                var t = GameDataValue.getLastLv(),
                    e = CacheDataManager.getChapterRoomId(t),
                    o = CacheDataManager.getLevelupgrade(e, t);
                if (o && o.length) {
                    var a = [];
                    CacheDataManager.logTask();
                    for (var i = 0; i < o.length; i++)
                        CacheDataManager.getGameTaskCount(i + "") &&
                            a.push({i: i, isBuy: !0, indexKey: i, dataItem: o[i]});
                    for (i = 0; i < a.length; i++) a[i].i = i;
                    var n = a.length;
                    this.checkLen(n);
                    this.listData = a;
                    if (n > 0) {
                        this._ListGrop.$ListGroupCom.setPutGetNode(
                            function () {
                                return QLooperNode.getNode(QLooperNode.tag_gameSkillItem);
                            },
                            function (t) {
                                QLooperNode.putNode(t);
                            }
                        );
                        this.updateView();
                    }
                }
                this.checkPig();
                this.updateView();
            };
            e.prototype.checkPig = function () {
                (GameDataValue.getLastLv() < 2 || !GameCof.isShopBool) && (this._topNode.active = !1);
            };
            e.prototype.updateCurPig = function () {
                var t = PayData.getProZsCount();
                t = Math.min(t, 700);
                this._countCenterLab.$Label.string = t + "";
                this._progress.$ProgressBar.progress = t / 700;
                if (t >= 700) {
                    this.playPigAnimal(1);
                    this._centerLab.$Label.string = "小猪存钱罐收集满啦";
                } else {
                    this.playPigAnimal(0);
                    this._centerLab.$Label.string = "升级以填充小猪存钱罐中的宝石！";
                }
            };
            e.prototype.playPigAnimal = function (t) {
                if (this._pig && this.lastIndex != t) {
                    this.lastIndex = t;
                    var e = this._pig.$Animation;
                    e.stop();
                    switch (t) {
                        case 0:
                            e.play("piganimal");
                            break;
                        case 1:
                            e.play("pigcoin");
                            break;
                        case 2:
                            e.play("pigjump");
                    }
                }
            };
            e.prototype.updateView = function () {
                var t = this.listData.length;
                this.checkLen(t);
                this._ListGrop.$ListGroupCom.reSetBaseInfo(t, 0, this.setitemaction.bind(this));
                this.updateCurPig();
            };
            e.prototype.updateAllViewCost = function () {
                var t;
                null === (t = this._ListGrop) || void 0 === t || t.$ListGroupCom.updateAllItem();
                this.updateCurPig();
            };
            e.prototype.setitemaction = function (t, e, o) {
                o || (o = {});
                if (!o.com) {
                    o.com = e.getComponent(p.default);
                    o.id = t;
                }
                for (var a = null, i = 0; i < this.listData.length; i++)
                    if (this.listData[i].i == t) {
                        a = this.listData[i];
                        break;
                    }
                if (o.com && a) {
                    e.active = !0;
                    var n = a.dataItem,
                        r = o.com;
                    r.tipLab1.string = "" + n.desc_title;
                    r.tipLab2.string = "" + n.desc_txt;
                    switch (n.upgrade_type) {
                        case 2:
                        case 3:
                            "0" == n.value1
                                ? SpriteView.setTaskSprite(r.coinSprite, n.icon1)
                                : SpriteView.setFoodSprite(r.coinSprite, CacheDataManager.getCheckIdFood(n.value1));
                            break;
                        default:
                            SpriteView.setTaskSprite(r.coinSprite, n.icon1);
                    }
                    SpriteView.setTaskSprite(r.coinSprite2, n.icon2);
                    var s = Math.max(1 - CacheDataManager.getAddAllAddtion(l.AddtionData.tisjZk)),
                        c = n.up_cost2;
                    if (1 != s)
                        for (var d = 0; d < 2; d++)
                            if (c > 0) {
                                c--;
                                s *= 10;
                            }
                    r.cost = ParseTool.getListCost(Math.floor(parseInt(n.up_cost) * s) + "", c);
                    r.costLab.string = "" + ParseTool.parseAbc(r.cost);
                    r.indexId = t;
                    r.updateView();
                } else e.active = !1;
            };
            e.prototype.uplockIndex = function (t, e, o, a) {
                var i = this;
                if (e < this.listData.length) {
                    for (var n = 0; n < this.listData.length; n++)
                        if (this.listData[n].i == e) {
                            this.scheduleOnce(function () {
                                CacheDataManager.setCoinCount(
                                    CacheDataManager.reduceCost(CacheDataManager.getCoinCount(), o)
                                );
                            });
                            var r = this.listData[n].dataItem;
                            CacheDataManager.setGameTaskOverCount(this.listData[n].indexKey, !0);
                            0 == GameDataValue.getLastLv() &&
                                QReport.sendOnce(1000001 + this.listData[n].indexKey + "");
                            this.listData.splice(e, 1);
                            EvCat.emit(EvCat.sendSkillTask, r.upgrade_type, r.value1, r.value2);
                            if (this._topNode.active) {
                                PayData.addPropZs(10);
                                var s = cc.v2(this._costLab.convertToWorldSpaceAR(cc.Vec2.ZERO));
                                EVUIEffView.emit(EVUIEffView.movePropSpriteIcon, a, s, "7002", !0, "10", 0.8);
                            }
                            this.scheduleOnce(function () {
                                i.updateCurPig();
                            }, 3.2);
                            break;
                        }
                    var c = this.listData.length;
                    for (n = 0; n < c; n++) this.listData[n].i = n;
                    var p = Math.min(c - 1, Math.max(this._ListGrop.$ListGroupCom.getCurIndex(), 0));
                    this._ListGrop.$ListGroupCom.reSetBaseInfo(c, p, this.setitemaction.bind(this));
                    this.checkLen(c);
                }
            };
            e.prototype.checkLen = function (t) {
                this._overView.active = 0 == t;
            };
            e.prototype.onCloseStart = function () {
                AdView.hideAd(d.AdTypeEm.implant);
                AdView.showAd(function () {
                    console.log("关闭店铺升级页面,展示插屏");
                }, d.AdTypeEm.closeSkill);
                QAudio.play(QAudio.ui_button);
                EVUIEffView.offTarget(this);
                this._ListGrop.$ListGroupCom.clearQLooperNode();
            };
            e.prototype._onOpenRewardTouchEnd = function () {
                c.default.open(s.UIID.UIValueAddPro);
            };
            return n([h], e);
        })(r.default));
o.default = f;
